package dba

import (
	"MBTIx/models"

	"github.com/jmoiron/sqlx"
)

func InsertTest(db *sqlx.DB, test models.Test) {
	db.NamedExec(
		`insert into test(user_id,create_date,answer)  
		values(:user_id,:create_date,:answer)`, test)
}

func GetTest(db *sqlx.DB, tests *[]models.Test){
	db.Select(tests,
	`select t1.user_id,t2.stu_name,t1.create_date,t1.answer from test t1, student t2 
	where t2.stu_id = t1.user_id order by id desc`)
}

func DeleteTest(db *sqlx.DB, user_id string){
	db.Exec(`delete from test where user_id = $1`, user_id)
}